home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 147 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  49 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Sorting huge files
  5. Date: 2 Jan 1996 21:06:58 GMT
  6. Organization: OpenVision
  7. Message-ID: <4cc6pi$dbk@spanky.pls.ov.com>
  8. References: <4c483b$ckd@longwood.cs.ucf.edu>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article ckd@longwood.cs.ucf.edu, schnitzi@longwood.cs.ucf.edu (Mark Schnitzius) writes:
  13. >glenn@ov.com (Fletcher.Glenn@ov.com) writes:
  14. >
  15. >>In article 317@news.dx.net, Todd Swanson <tswan@sinnfree.sinnfree.org> writes:
  16. >>>I'm having troubles sorting large files.  Smaller files are no problem I 
  17. >>>can read the fields into arrays.  Then sort the pointers to the arrays 
  18. >>><simple>.  However, larger files are a problem because I cant store the 
  19. >>>entire file into an array.  Is there any one who has some source, or 
  20. >>>could explain an algorithm to help me?  I was thinking of using memory as 
  21. >>>a buffer, and use the disk as a swap space; perhaps, a "virtual sort"?  I 
  22. >>>have been using bubble sort logic for this virtual sort, but I'm not sure 
  23. >>>how to sort the file in chunks, yet manage to sort the entire file.  
  24. >
  25. >>Consider the following:
  26. >
  27. >>1.  Read in a chunk of the file, and sort that chunk.  Write the sorted 
  28. >>    chunk to another file.
  29. >
  30. >[...etc...]
  31. >
  32. >Better still to just use fseek and ftell to move about in the file.
  33. >Make an int array of lines where you save the result of an ftell
  34. >before reading that line.  Then you can use fseek to go back and
  35. >read that line in again before making a comparison.  Not terribly
  36. >efficient but it gets the job done.
  37. >
  38. >
  39. >_____________________________________________________________
  40. >mark schnitzius - - - - - - - - - - - - - schnitzi@mentos.com
  41. >- - - -<a href="http://east.isx.com/~schnitzi/">me</a>- - - -
  42.  
  43.  
  44. Tell me, exactly how does your method result in a sorted file?
  45.  
  46.             Fletcher.Glenn@ov.com
  47.  
  48.  
  49.